/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package ac.reportes;

import ac.lib.database.dbconnection;
import ac.settings.dataModel;
import ac.settings.files;

import java.awt.Dimension;

import java.io.InputStream;
import javax.swing.JFrame;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.engine.design.JasperDesign;
import net.sf.jasperreports.engine.xml.JRXmlLoader;
import net.sf.jasperreports.swing.JRViewer;

/**
 *
 * @author empcl_000
 */
public class reportes extends dbconnection implements files, dataModel {

    public String tabel;
    public String Name;
    public String cdata = "";
    public String where;
    public String Query = "";

    ac.lib.database.operations db = new ac.lib.database.operations();

    public static void updateReporteTitles(String title, String usbtitle1, String usbtitle2, String usbtitle3, String usbtitle4) {

        ac.lib.database.operations db = new ac.lib.database.operations();

        String[][] usedata = {
            new String[]{"title", "usbtitle1", "usbtitle2", "usbtitle3", "usbtitle4"}, 
            new String[]{title, usbtitle1, usbtitle2, usbtitle3, usbtitle4}};

        db.setUpdate(TABLE_print_options, usedata, "1=1");

    }

    public void craeteReporte() {

        db.ctareViewData(tabel, Name, cdata, where);
        String test = db.retuenErrorMessage;
    }

    public void craeteReporteFromQuery() {

        db.ctareViewDataFromQuery(Name, Query);
        String test = db.retuenErrorMessage;
    }

    public void showReport(String url) {

        try {

            setOpenCon();

            InputStream is = reportes.class.getResourceAsStream(url);
            JasperDesign jasperDesign = JRXmlLoader.load(is);
            JasperReport jr = JasperCompileManager.compileReport(jasperDesign);
            //Fill the report with parameter, connection and the stream reader     
            JasperPrint jp;
            jp = JasperFillManager.fillReport(jr, null, con);

            //Viewer for JasperReport
            JRViewer jv = new JRViewer(jp);

            //Insert viewer to a JFrame to make it showable
            JFrame jf = new JFrame();
            jf.getContentPane().add(jv);
            jf.validate();
            jf.setVisible(true);
            jf.setSize(new Dimension(800, 600));
            jf.setLocation(300, 100);
            jf.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
            jf.setVisible(true);
        } catch (JRException ex) {
            String r = ex.getMessage();
            System.out.print(ex.getMessage());
            ex.printStackTrace();
        }

    }
}
